# 信号灯相关
from typing import Optional

from fastapi import APIRouter

from core import curd
from models.light import Light
from scheams import Light_Pydantic, LightIn_Pydantic, BaseResponse

light = APIRouter()


@light.post("/create", summary="新增信号灯", response_model=BaseResponse)
async def create_light(light_form: LightIn_Pydantic):
    return await curd.create(Light, light_form)


@light.delete("/delete", summary="删除信号灯")
async def delete_light(pk: int):
    return await curd.delete(Light, pk)


@light.put("/update", summary="修改信号灯", response_model=BaseResponse)
async def update_light(pk: int, light_form: LightIn_Pydantic):
    return await curd.update(Light, light_form, pk)


@light.get("/read", summary="获取信号灯", response_model=BaseResponse)
async def read_light(pk: int):
    return await curd.read(Light, pk, Light_Pydantic)


@light.get("/list", summary="获取所有信号灯", response_model=BaseResponse)
async def get_light_list(limit: Optional[int] = 0, page: Optional[int] = 0):
    return await curd.get_list(Light, Light_Pydantic, page, limit)
